﻿#include "stdafx.h"
#include "../../GameCore/CGame.h"


void CItem::Init(int id, int type, float baseX, float baseY)
{
	_id = id;
	_type = type;
	_baseX = baseX;
	_baseY = baseY;
	_targetY = k_SCREEN_HEIGHT - 25;
	_state = ITEM_STATE_MOVE;
	_speed = ITEM_SPEED + GET_GAME()->GetCurrentLevel()*10;
}

void CItem::Update()
{
	if(MoveTo(_targetX, _targetY))
	{
		_state = ITEM_STATE_DIE;
		if(_type == _IMAGE_TYPE_EGG)
			GET_GAME()->RemoveCharaterHP();
	}
	if(GET_GAME()->CheckCircleAndRect(_baseX, _baseY, 25, GET_GAME()->_basket_posX, GET_GAME()->_basket_posY, 100, 75))
	{
		_state = ITEM_STATE_DIE;
		if(_type == _IMAGE_TYPE_EGG)
		{
			GET_GAME()->AddEggs();
		}
		else
		{
			GET_GAME()->RemoveCharaterHP();
		}
	}
}

void CItem::Render()
{
	if(_type == _IMAGE_TYPE_EGG || _type == _IMAGE_TYPE_SHIT)
		GL()->SetScale(0.5, 0.5, _baseX, _baseY);
	GET_SPRITE().DrawTexture(GL(), _type, _baseX, _baseY);
	GL()->ClearScale();
}

bool CItem::MoveTo(float targetX, float targetY)
{	
	_baseY += (_speed*GET_GAME()->_frame_dt)/1000; //speed (pixel/s)
	if(_baseY >= targetY)
		return true;
	return false;
}

